//
//  HomeTitleButton.swift
//  WeiBoSwift
//
//  Created by rong on 15/6/29.
//  Copyright © 2015年 rong. All rights reserved.
//

import UIKit

class HomeTitleButton: UIButton {

    
    class func button(tittle: String) -> HomeTitleButton {
    
        let titleBtn = HomeTitleButton()
        //titleBtn.frame = CGRectMake(0, 0, 120, 30) 这里设置成  sizeToFit()
        
        titleBtn.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        titleBtn.titleLabel!.font = UIFont.systemFontOfSize(17.0)
        titleBtn.setTitle(tittle, forState: UIControlState.Normal)
        titleBtn.setImage(UIImage(named: "navigationbar_arrow_down"), forState: UIControlState.Normal)
        titleBtn.sizeToFit()
        
        return titleBtn
    }
    
    // 设置子控件布局 的
    override func layoutSubviews() {
        super.layoutSubviews()
        
        //btn 的 label
        var tFrame = titleLabel!.frame
        tFrame.origin.x = 0
        titleLabel!.frame = tFrame
        
        //btn 的 imageView
        var iFrame = imageView!.frame
        iFrame.origin.x = tFrame.width+5 //文字和图片之间有 5 的间隙
        imageView!.frame = iFrame
        
    }

}
